﻿
#include "iostream"
#include "string"
#include "utilities/Inc/log.h"
#include "main/Inc/img_buffer.h"

ImgBuffer::ImgBuffer() : _lock(6),_frames(6), _tailIdx(0), _headIdx(0)
{

}

bool ImgBuffer::GetImage(cv::Mat &src)
{
    volatile const size_t headIdx = _headIdx;
    src = _frames[headIdx];
    return true;
}


bool ImgBuffer::ImgEnterBuffer(cv::Mat &src)
{
    const int newHeadIdx = (_headIdx + 1) % _frames.size();
    _frames[newHeadIdx] = src;
    if (newHeadIdx == _tailIdx)
    {
        _tailIdx = (_tailIdx + 1) % _frames.size();
    }
    _headIdx = newHeadIdx;
    return true;
}
